/*     */ package com.cr.common.utils.security;
/*     */ 
/*     */ import com.cr.common.utils.MessageUtils;
/*     */ import java.beans.BeanInfo;
/*     */ import java.beans.Introspector;
/*     */ import java.beans.PropertyDescriptor;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.apache.shiro.SecurityUtils;
/*     */ import org.apache.shiro.subject.Subject;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ 
/*     */ public class PermissionUtils {
/*  21 */   private static final Logger log = LoggerFactory.getLogger(PermissionUtils.class);
/*     */   
/*     */   public static final String VIEW_PERMISSION = "no.view.permission";
/*     */   
/*     */   public static final String CREATE_PERMISSION = "no.create.permission";
/*     */   
/*     */   public static final String UPDATE_PERMISSION = "no.update.permission";
/*     */   
/*     */   public static final String DELETE_PERMISSION = "no.delete.permission";
/*     */   
/*     */   public static final String EXPORT_PERMISSION = "no.export.permission";
/*     */   
/*     */   public static final String PERMISSION = "no.permission";
/*     */   
/*     */   public static String getMsg(String permissionsStr) {
/*  61 */     String permission = StringUtils.substringBetween(permissionsStr, "[", "]");
/*  62 */     String msg = MessageUtils.message("no.permission", new Object[] { permission });
/*  63 */     if (StringUtils.endsWithIgnoreCase(permission, "add")) {
/*  65 */       msg = MessageUtils.message("no.create.permission", new Object[] { permission });
/*  67 */     } else if (StringUtils.endsWithIgnoreCase(permission, "edit")) {
/*  69 */       msg = MessageUtils.message("no.update.permission", new Object[] { permission });
/*  71 */     } else if (StringUtils.endsWithIgnoreCase(permission, "remove")) {
/*  73 */       msg = MessageUtils.message("no.delete.permission", new Object[] { permission });
/*  75 */     } else if (StringUtils.endsWithIgnoreCase(permission, "export")) {
/*  77 */       msg = MessageUtils.message("no.export.permission", new Object[] { permission });
/*  79 */     } else if (StringUtils.endsWithAny(permission, (CharSequence[])new String[] { "view", "list" })) {
/*  82 */       msg = MessageUtils.message("no.view.permission", new Object[] { permission });
/*     */     } 
/*  84 */     return msg;
/*     */   }
/*     */   
/*     */   public static Object getPrincipalProperty(String property) {
/*  95 */     Subject subject = SecurityUtils.getSubject();
/*  96 */     if (subject != null) {
/*  98 */       Object principal = subject.getPrincipal();
/*     */       try {
/* 101 */         BeanInfo bi = Introspector.getBeanInfo(principal.getClass());
/* 102 */         for (PropertyDescriptor pd : bi.getPropertyDescriptors()) {
/* 104 */           if (pd.getName().equals(property) == true)
/* 106 */             return pd.getReadMethod().invoke(principal, (Object[])null); 
/*     */         } 
/* 110 */       } catch (Exception e) {
/* 112 */         log.error("Error reading property [{}] from principal of type [{}]", property, principal
/* 113 */             .getClass().getName());
/*     */       } 
/*     */     } 
/* 116 */     return null;
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-common-4.7.0.jar!\com\cr\commo\\utils\security\PermissionUtils.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */